/*
 * @Descripttion: 文件说明
 * @version: 0.0.1
 * @Author: ZhangMeng
 * @Date: 2024-08-27 09:14:12
 * @LastEditors: ZhangMeng
 * @LastEditTime: 2024-08-27 16:39:41
 */
import { app, BrowserWindow, Menu } from 'electron';
import { join } from 'path';
import { fileURLToPath } from 'node:url';
import path from 'node:path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const ROOT_PATH = {
    // src
    src: join(__dirname, "./src"),
    // public
    public: join(__dirname, "./public"),
};

const INDEX_HTML = join(ROOT_PATH.public, "index.html");

let win = null;
// 将页面加载到 BrowserWindow 实例中
const createWindow = () => {
    win = new BrowserWindow({
        width: 800,
        height: 600,
        frame: true, // 无边框
        icon: join(ROOT_PATH.public, '/logo.png'), // 设置窗口图标
        resizable: true,
        show: true
    });

    // 导航菜单
    const menuBuilder = new Menu.buildFromTemplate([])
    Menu.setApplicationMenu(menuBuilder);

    win.loadFile(INDEX_HTML);
}


// 应用准备就绪时调用函数
app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) {
            createWindow()
        }
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        win = null;
        app.quit();
    }
})
